import assign from 'object-assign';
import {observable, useStrict, action, runInAction} from 'mobx';
import {browserHistory} from 'react-router';

class UserStore {
    @observable data = [];

    @observable noChangeData = {
        url : '',
        page : 0,
        size : 20,
        type : 'json',
        hasNext : true
    }
    @action initData(param) {
        this.data = param;
    }

    @action ajaxData(param) {
        if (!this.noChangeData.url) {
            return;
        }
        $.ajax({
            context : this,
            url : this.noChangeData.url,
            data : {
                page : ++this.noChangeData.page,
                size : this.noChangeData.size,
                type : 'json'
            },
            success : function (res) {
                if(res.dataArray){
                    this.data.push.apply(this.data,res.dataArray);
                }
            }
        });
    }

    @action _init(options){
        assign(this.noChangeData,options);
    }

}
const User = new UserStore();
export default User;
